package leader.action;

import java.util.ArrayList;
import java.util.List;

import leader.service.DirectTeacherService;
import leader.service.LeaderService;

import com.opensymphony.xwork2.ActionContext;

import teacher.bean.Award;
import teacher.bean.Teacher;

public class AllDirectTeacherAction {
	private List<Teacher> teacher;
	private int currentpage;
	private int pagesize;
	private int endpage;
	private int count;
	private int sum;

	public List<Teacher> getTeacher() {
		return teacher;
	}

	public void setTeacher(List<Teacher> teacher) {
		this.teacher = teacher;
	}
	
	
	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public int getEndpage() {
		return endpage;
	}

	public void setEndpage(int endpage) {
		this.endpage = endpage;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public int getSum() {
		return sum;
	}

	public void setSum(int sum) {
		this.sum = sum;
	}

	public String execute() {
		Teacher lea=(Teacher) ActionContext.getContext().getSession().get("leader");
    	DirectTeacherService TS = new DirectTeacherService(); 
    	sum = TS.getCountOfTeacher(lea);
		pagesize = 10;
		count = TS.getCountOfTeacher(lea);
    	List<Award> awards = new ArrayList<Award>();
    	if(currentpage == 0) {
    		currentpage = 1;
    	}
    	int add = 0;
    	if(count%pagesize != 0) {
    		add = 1;
    	}
    	endpage = count/pagesize + add;
    	if(currentpage > endpage && endpage > 0 ) {
    		currentpage = endpage;
    	}
		teacher = TS.selectSegregateAllTeacher(lea, (currentpage-1)*pagesize+1, pagesize);
		return "success";
	}
}
